﻿using System;
using System.Collections.Generic;

namespace CodeContrib.Caching
{
	public class CacheItem
	{
		public DateTime AbsoluteExpiration { get; set; }
		public IEnumerable<string> DependentSets { get; set; }
		public string Key { get; set; }

		public int KeyHashCode
		{
			get { return Key.GetHashCode(); }
		}

		public DateTime LastAccessedAt { get; set; }
		internal CacheItem Next { get; set; }
		internal CacheItem Previous { get; set; }
		public TimeSpan SlidingExpiration { get; set; }
		public object Value { get; set; }

		public override bool Equals(object obj)
		{
			var other = obj as CacheItem;

			if (other == null)
			{
				return false;
			}

			return Equals(other);
		}

		public bool Equals(CacheItem other)
		{
			Guard.NotNull(other, "other");

			if (KeyHashCode != other.KeyHashCode)
			{
				return false;
			}

			return Key.Equals(other.Key, StringComparison.Ordinal);
		}

		public override int GetHashCode()
		{
			return KeyHashCode;
		}
	}
}